import { Injectable } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { QueryOptions } from 'src/app/project/model/common/query-options';
import { Observable } from 'rxjs';
import { ApiPagedData } from 'src/app/project/model/common/api-paged-data';
import { StudentCourseGradeGatherDTO } from 'src/app/project/model/icm/icm-student-academic/student-score/student-course-grade-gather.dto';

@Injectable({
  providedIn: 'root',
})
export class StudentScoreGratherService {
  private static URL = '/api/icm-student-course-grade-grather';

  constructor(private http: _HttpClient) {}

  /**
   * 分页查找学生成绩汇总
   * @param option 分页参数
   * @param studentId 学生id
   * @param year 学年
   * @param termType 学期
   */
  findOnePage(
    option: QueryOptions,
    studentId?: string,
    year?: string,
    termType?: string,
  ): Observable<ApiPagedData<StudentCourseGradeGatherDTO>> {
    const params = {};
    Object.assign(params, option, studentId ? { studentId } : {}, year ? { year } : {}, termType ? { termType } : {});
    return this.http.get<ApiPagedData<StudentCourseGradeGatherDTO>>(StudentScoreGratherService.URL, params);
  }

  /**
   * 根据学年、学期模糊查找学生课程成绩汇总
   * @param studentCode 学生学号
   * @param year 学年
   * @param termType 学期
   */
  search(studentCode?: string, year?: string, termType?: string): Observable<Array<StudentCourseGradeGatherDTO>> {
    const params = {};
    Object.assign(params, studentCode ? { studentCode } : {}, year ? { year } : {}, termType ? { termType } : {});
    return this.http.get<Array<StudentCourseGradeGatherDTO>>(`${StudentScoreGratherService.URL}/search`, params);
  }
}
